import regeneratorRuntime from '../../lib/runtime/runtime'
import {
  request
} from '../../request/index'
import {
  login
} from '../../utils/asyncWx'
Page({

  data: {

  },

  onLoad: function (options) {

  },

  async handleGetUserInfo(e) {
    try {
      //获取用户信息
      const {
        encryptedData,
        iv,
        rawData,
        signature
      } = e.detail

      //获取code
      const {
        code
      } = await login()

      //发送请求 获取用户token

      const loginParams = {
        encryptedData,
        iv,
        rawData,
        signature,
        code
      }

      const res = await request({
        url: "/users/wxlogin",
        data: loginParams,
        method: "post"
      }, )

      let token = "Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1aWQiOjIzLCJpYXQiOjE1NjQ3MzAwNzksImV4cCI6MTAwMTU2NDczMDA3OH0.YPt-XeLnjV-_1ITaXGY2FhxmCe4NvXuRnRB8OMCfnPo";
      wx.setStorageSync("token", token);


      wx.navigateBack({
        delta: 1
      });

    } catch (errpr) {
      console.log(error);
    }



  }

})